<template>
  <div>
    <h2 style="text-align: center;">注册页面</h2>
    <table class="table table-bordered">
      <tr>
        <td>用户名</td>
        <td><input type="text" v-model="info.zname"></td>
      </tr>
      <tr>
        <td>密码</td>
        <td><input type="password" v-model="info.zpwd"></td>
      </tr>
      <tr>
        <td colspan="2">
          <input type="button" value="注册" @click="zhuce">
        </td>

      </tr>
    </table>

  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue';
import axios from 'axios';
import { useRouter } from 'vue-router';
let router=useRouter();

const info=ref({
  zname:"",
  zpwd:"",
})

//注册函数
const zhuce=()=>{
  if(info.value.zname=="")
  {
    alert("用户名不能为空");
    return;

  }
  if(info.value.zpwd=="")
  {
    alert("密码不能为空");
    return;
  }

  axios({
    url:"http://localhost:1041/api/User/Add",
    method:"post",
    data:info.value
  }).then
  (
    (res)=>{
      if(res.data==-1)
      {
          alert("用户已存在");
      }
     else if(res.data>0)
      {
        alert("注册成功");
        router.push("/LoginView");

      }
      else
      {
        alert("注册失败");
      }
    }
  )



}




</script>

<style scoped>

</style>